<?php
/**
 * Created by PhpStorm.
 * User: zouhua
 * Date: 2017/6/17
 * Time: 16:58
 */

namespace app\actions;

use app\models\Activity;

class ActivityIndexAction extends UserList {

    public function beforeRun() {
        if (!parent::beforeRun()) {
            return FALSE;
        }

        $defaultCid = Activity::CID_SHA_LONG;

        $cid = $this->getParam('cid');
        if (NULL === $cid) {
            \Yii::$app->request->setQueryParams(['cid' => $defaultCid]);
        }

        if (!isset(Activity::$cidLabels[$cid])) {
            $cid = $defaultCid;
        }

        $this->controller->view->params['banner_type'] = $cid;
        $this->where = ['cid' => $cid, 'status' => [Activity::STATUS_PENDING, Activity::STATUS_RUNNING]];
        $this->title = Activity::$cidLabels[$cid];
        $this->orderBy = 'status asc, id desc';

        return TRUE;
    }
}